package com.utils; /**
 * @authon :ZXL
 * @date :2022/10/9
 */

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter("/Teacher.jsp")
public class FilterB implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {

        HttpServletRequest req = (HttpServletRequest) request;
        Object user = req.getSession().getAttribute("user");

        if (user !=null){
            chain.doFilter(request, response);
        }else {
            req.setAttribute("msg","您尚未登录");
            req.getRequestDispatcher("/login.jsp").forward(req,response);
        }

    }
}